package com.sxdz.controller.service.goods

import com.sxdz.controller.mapper.TGoodsInfoMapper
import com.sxdz.controller.service.BaseService
import com.sxdz.models.TGoodsInfo
import com.sxdz.models.common.Order
import com.sxdz.models.common.RollPage
import com.toolbox.utils.ClearNullUtil
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
/**
 * Created by LiYan on 2016/8/4.
 */
@Service
@CompileStatic
@TypeChecked
class GoodsService extends BaseService implements IGoodsService{

    private  TGoodsInfoMapper tGoodsInfoMapper;
    @Autowired
    private setTGoodsInfoMapper(TGoodsInfoMapper tGoodsInfoMapper){
    this.tGoodsInfoMapper=tGoodsInfoMapper;
        super.baseMapper=tGoodsInfoMapper;
    }

    @Override
    Long addBasic(def obj) throws Exception {}

    @Override
    void modifyBasic(def obj) throws Exception {}

    @Override
    void delBasic(def obj) throws Exception {}

    List<TGoodsInfo> findListByParams(Map<String, Object> params){
        List<TGoodsInfo> list=new ArrayList<TGoodsInfo>()
            list=tGoodsInfoMapper.selectListByParams(params,null,null,null)
        return list
    }

    @Override
    TGoodsInfo selectByPrimaryKey(Long id) {
        return tGoodsInfoMapper.selectByPrimaryKey(id);
    }

    TGoodsInfo findObj(Map<String, Object> params){
        return tGoodsInfoMapper.selectByParams(params)
    }

    /*List<Map<String,Object>> findListByModule(){
        return tGoodsInfoMapper.findListByModule()
    }*/

    @Override
    RollPage findListByModule(Map<String, Object> params, Order order, Integer pageNum, Integer pageSize) throws Exception {
        ClearNullUtil.mapClear(params)
        Integer recordSum= tGoodsInfoMapper.selectCountByModule(params)
        Integer pageSizeCustom = this.pageSizeDefault
        RollPage rollPage=new RollPage(iTotalRecords:recordSum,iTotalDisplayRecords:recordSum,pageSize:pageSize?:pageSizeCustom,pageNum: pageNum?:1)

        Integer pageOffset=(rollPage.getPageNum() - 1) * rollPage.getPageSize()

        if (recordSum>0) {
            rollPage.recordList =tGoodsInfoMapper.findListByModule(params, pageOffset, rollPage.pageSize, order?.toString())
        }
        else{
            rollPage.recordList = []
        }

        rollPage;
    }

    @Override
    Integer findCountByModule(Map<String, Object> params) {
        return tGoodsInfoMapper.selectCountByModule(params)
    }
}
